package cn.ys.org.dto;

import cn.ys.base.util.MD5Utils;
import cn.ys.base.util.StrUtils;
import cn.ys.user.domain.User;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.Date;

@Data
public class BinderDto {

    @NotBlank(message = "手机不能为空")
    private String phone;
    @NotBlank(message = "verifyCode不能为空")
    private String verifyCode;
    @NotBlank(message = "accessToken不能为空")
    private String accessToken;
    @NotBlank(message = "openId不能为空")
    private String openId;

    public User getUser() {
        // 通过盐值加密码加密
        // 获取盐值
        String salt = StrUtils.getComplexRandomString(32);
        String byMd5 = MD5Utils.encrypByMd5(salt + 1);
        return User.builder()
                .salt(salt)
                .password(byMd5)
                .phone(this.phone)
                .state(1)
                .username(this.phone)
                .createtime(new Date())
                .build();
    }
}
